'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const f = require('./identity.cjs');
function i(e, t, r) {
  if (Array.isArray(e)) return e.map((n, o) => i(n, String(o), r));
  if (e && typeof e.toJSON == 'function') {
    if (!r || !f.hasAnchor(e)) return e.toJSON(t, r);
    const n = { aliasCount: 0, count: 1, res: void 0 };
    r.anchors.set(e, n),
      (r.onCreate = s => {
        (n.res = s), delete r.onCreate;
      });
    const o = e.toJSON(t, r);
    return r.onCreate && r.onCreate(o), o;
  }
  return typeof e == 'bigint' && !(r != null && r.keep) ? Number(e) : e;
}
exports.toJS = i;
